#pragma once

#include <mutex>
#include <condition_variable>
#include <atomic>

namespace Dict
{

    class WaitCount
    {
    public:
        WaitCount(int init_cnt = 1)
            :_count(init_cnt)
        {}
        void wait()
        {
            std::unique_lock<std::mutex> lock(_mtx);
            _cond.wait(lock,[this]()
            {
                //这里会释放锁，满足条件后会在再次加锁
               return _count == 0;
            });
            std::cout<<"解锁"<<std::endl;
        }
        void Reduction()
        {
            std::lock_guard<std::mutex> lock(_mtx);
            --_count;
            _cond.notify_one();
        }
    private:
        int _count;
        std::mutex _mtx;
        std::condition_variable _cond;
    };

}